<template>
  <div class="home-page">
    <!-- 标题区域 -->
    <div class="title-section">
      <h1 class="main-title">宝可梦图鉴</h1>
      <p class="subtitle">发现你的宝可梦伙伴</p>
    </div>
    
    <!-- 搜索区域 -->
    <div class="search-section">
      <!-- 基础搜索框 -->
      <div class="basic-search">
        <div class="search-bar">
          <el-input
            v-model="searchKeyword"
            placeholder="使用名称或图鉴编号搜索"
            class="search-input"
            size="large"
            @keyup.enter="performSearch"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
          <el-button 
            type="primary" 
            size="large" 
            @click="performSearch"
            class="search-btn"
          >
            <el-icon><Search /></el-icon>
            搜索
          </el-button>
          <el-button 
            type="warning" 
            size="large" 
            @click="getRandomPokemon"
            class="random-btn"
          >
            <el-icon><Refresh /></el-icon>
            随机显示
          </el-button>
        </div>
      </div>
      
      <!-- 高级搜索切换按钮 -->
      <div class="advanced-toggle">
        <el-button 
          @click="showAdvancedSearch = !showAdvancedSearch"
          type="info"
          size="default"
          text
        >
          <el-icon><Setting /></el-icon>
          {{ showAdvancedSearch ? '收起高级搜索' : '高级搜索' }}
        </el-button>
      </div>
      
      <!-- 高级搜索面板 -->
      <el-collapse-transition>
        <div v-show="showAdvancedSearch" class="advanced-search">
          <div class="search-filters">
            <!-- 属性筛选 -->
            <div class="filter-section">
              <h4 class="filter-title">属性</h4>
              <div class="type-filters">
                <div 
                  v-for="type in pokemonTypes" 
                  :key="type"
                  class="type-filter"
                  :class="{ active: selectedTypes.includes(type) }"
                  @click="toggleType(type)"
                >
                  <span class="type-badge" :class="`type-${type}`">{{ type }}</span>
                </div>
              </div>
            </div>
            
            <!-- 特性和图鉴范围筛选 -->
            <div class="filter-section filter-row">
              <!-- 特性筛选 -->
              <div class="filter-column">
                <h4 class="filter-title">特性</h4>
                <div class="category-selector">
                  <el-select
                    v-model="selectedCategory"
                    placeholder="输入或选择特性"
                    size="large"
                    style="width: 240px"
                    clearable
                    filterable
                    allow-create
                    default-first-option
                    :reserve-keyword="false"
                    @change="onCategoryChange"
                  >
                    <el-option
                      v-for="category in pokemonCategories"
                      :key="category"
                      :label="category"
                      :value="category"
                    />
                  </el-select>
                  <div class="category-hint">
                    <el-icon><InfoFilled /></el-icon>
                    <span>可直接输入特性名称快速搜索</span>
                  </div>
                </div>
              </div>
              
              <!-- 编号范围筛选 -->
              <div class="filter-column">
                <h4 class="filter-title number-range-title">
                  图鉴No. {{ numberRange.min }} - {{ numberRange.max }}
                </h4>
                <div class="number-range-slider">
                  <el-slider
                    v-model="numberRange.values"
                    range
                    :min="1"
                    :max="166"
                    :step="1"
                    show-tooltip
                    :format-tooltip="formatTooltip"
                    @change="onRangeChange"
                  />
                  <div class="range-labels">
                    <span class="range-label-min">1</span>
                    <span class="range-label-max">166</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
          <!-- 搜索操作按钮 -->
          <div class="search-actions">
            <el-button @click="resetFilters" size="large" class="reset-btn">重置筛选</el-button>
            <el-button type="primary" @click="applyAdvancedSearch" size="large">应用筛选</el-button>
          </div>
        </div>
      </el-collapse-transition>
    </div>
    
    <!-- 宝可梦卡片网格 -->
    <div class="pokemon-grid">
      <div 
        v-for="pokemon in pokemonList" 
        :key="pokemon.id"
        class="pokemon-card"
        :style="{ backgroundColor: getPrimaryTypeColor(pokemon) }"
        @click="selectPokemon(pokemon)"
      >
        <div class="card-inner">
          <div class="pokemon-image">
            <img :src="getPokemonImage(pokemon)" :alt="getPokemonName(pokemon)">
          </div>
          <div class="pokemon-number">#{{ getPokemonNumber(pokemon) }}</div>
          <h3 class="pokemon-name">{{ getPokemonName(pokemon) }}</h3>
          <div class="pokemon-types">
            <span 
              v-for="type in getPokemonTypes(pokemon)" 
              :key="type" 
              class="type-badge" 
              :class="`type-${type}`"
            >
              {{ type }}
            </span>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 加载状态 -->
    <div v-if="loading && pokemonList.length === 0" class="loading-state">
      <div class="loading-content">
        <div class="pokeball-loading">
          <div class="pokeball">
            <div class="pokeball-top"></div>
            <div class="pokeball-bottom"></div>
            <div class="pokeball-center"></div>
          </div>
        </div>
        <p>正在加载宝可梦数据...</p>
      </div>
    </div>
    
    <!-- 空状态 -->
    <div v-else-if="!loading && pokemonList.length === 0" class="empty-state">
      <div class="empty-content">
        <div class="empty-icon">🔍</div>
        <h3>暂无宝可梦数据</h3>
        <p>请检查网络连接或稍后重试</p>
        <el-button @click="fetchPokemonList" type="primary">重新加载</el-button>
      </div>
    </div>
    
    <!-- 加载更多按钮 -->
    <div class="load-more" v-if="hasMore && pokemonList.length > 0">
      <el-button @click="loadMore" :loading="loading" size="large">
        {{ loading ? '加载中...' : '加载更多' }}
      </el-button>
    </div>
    
    <!-- 宝可梦详情弹窗 -->
    <el-dialog
      v-model="dialogVisible"
      :title="selectedPokemon?.pokemonName"
      width="600px"
      center
    >
      <div v-if="selectedPokemon" class="pokemon-detail">
        <div class="detail-image">
          <img :src="getPokemonImage(selectedPokemon)" :alt="getPokemonName(selectedPokemon)">
        </div>
        <div class="detail-info">
          <p><strong>编号:</strong> #{{ getPokemonNumber(selectedPokemon) }}</p>
          <p><strong>身高:</strong> {{ selectedPokemon.height }}m</p>
          <p><strong>体重:</strong> {{ selectedPokemon.weight }}kg</p>
          <p><strong>属性:</strong> 
            <span 
              v-for="type in selectedPokemon.types" 
              :key="type.id"
              class="type-badge"
              :class="`type-${type.typeName.replace('系', '')}`"
            >
              {{ type.typeName }}
            </span>
          </p>
          <p><strong>描述:</strong> {{ selectedPokemon.description || '暂无描述' }}</p>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, watch } from 'vue'
// 导入相关API
import { 
  getPokemonList, 
  getPokemonListByVO, 
  getGen1Pokemon, 
  getMockPokemonList,
  searchPokemon,
  getPokemonByType,
  getPokemonByCategory,
  getPokemonByNumberRange
} from '@/api/pokemon.api.js'
// 移除了所有提示
import { Search, Refresh, Setting, InfoFilled } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'

// 路由实例
const router = useRouter()

// 响应式数据
const pokemonList = ref([])
const allPokemonData = ref([]) // 存储所有宝可梦数据，用于搜索
const loading = ref(false)
const hasMore = ref(true)
const currentPage = ref(1)
const pageSize = ref(20)
const dialogVisible = ref(false)
const selectedPokemon = ref(null)

// 基于本地全量数据进行切片展示，避免重复
const updateDisplayList = () => {
  const total = allPokemonData.value.length
  const visibleCount = Math.min(currentPage.value * pageSize.value, total)
  pokemonList.value = allPokemonData.value.slice(0, visibleCount)
  hasMore.value = visibleCount < total
}

// 搜索相关数据
const searchKeyword = ref('')
const showAdvancedSearch = ref(false)
const selectedTypes = ref([])
const selectedCategory = ref('')
const numberRange = ref({ 
  min: 1, 
  max: 166, 
  values: [1, 166] // 双滑块的值数组
})

// 宝可梦属性列表
const pokemonTypes = ref([
  '一般', '火', '水', '电', '草', '冰', '格斗', '毒', 
  '地面', '飞行', '超能力', '虫', '岩石', '幽灵', '龙', 
  '恶', '钢', '妖精'
])

// 中文属性名到英文的映射
const typeNameMap = {
  '一般': 'normal',
  '火': 'fire',
  '水': 'water',
  '电': 'electric',
  '草': 'grass',
  '冰': 'ice',
  '格斗': 'fighting',
  '毒': 'poison',
  '地面': 'ground',
  '飞行': 'flying',
  '超能力': 'psychic',
  '虫': 'bug',
  '岩石': 'rock',
  '幽灵': 'ghost',
  '龙': 'dragon',
  '恶': 'dark',
  '钢': 'steel',
  '妖精': 'fairy'
}

// 属性颜色映射（去掉"系"字的属性名）
const typeColors = {
  '一般': '#A8A878',
  '火': '#F08030',
  '水': '#6890F0',
  '电': '#F8D030',
  '草': '#78C850',
  '冰': '#98D8D8',
  '格斗': '#C03028',
  '毒': '#A040A0',
  '地面': '#E0C068',
  '飞行': '#A890F0',
  '超能力': '#F85888',
  '虫': '#A8B820',
  '岩石': '#B8A038',
  '幽灵': '#705898',
  '龙': '#7038F8',
  '恶': '#705848',
  '钢': '#B8B8D0',
  '妖精': '#EE99AC'
}

// 转换中文属性名为英文
const convertTypeToEnglish = (chineseType) => {
  return typeNameMap[chineseType] || chineseType
}

// 宝可梦分类列表（从数据中动态获取）
const pokemonCategories = computed(() => {
  const categories = new Set()
  allPokemonData.value.forEach(pokemon => {
    if (pokemon.category) {
      categories.add(pokemon.category)
    }
  })
  return Array.from(categories).sort()
})

// 获取宝可梦列表
const fetchPokemonList = async (page = 1, append = false) => {
  try {
    loading.value = true
    
    let response
    try {
      // 优先获取前151只宝可梦（第一世代）
      console.log('正在从后端获取第一世代宝可梦数据...')
      response = await getGen1Pokemon()
    } catch (gen1Error) {
      // 移除了控制台提示
      try {
        // 如果第一世代API失败，获取所有宝可梦
        response = await getPokemonList()
      } catch (allError) {
        // 移除了控制台提示
        // 如果所有API都失败，使用模拟数据
        response = await getMockPokemonList()
      }
    }
    
    // 处理响应数据
    if (response) {
      // 如果response直接是数据数组（request.js已经处理了flag检查）
      const newPokemons = Array.isArray(response) ? response : (response.data || [])
      
      // 全量替换数据并重置分页，由前端切片避免重复
      allPokemonData.value = newPokemons.slice()
      
      // 对数据按编号排序，确保显示顺序正确
      allPokemonData.value.sort((a, b) => {
        const numA = parseInt(a.number || a.id || 0)
        const numB = parseInt(b.number || b.id || 0)
        return numA - numB
      })
      
      currentPage.value = 1
      updateDisplayList()
      
      console.log(`成功获取 ${newPokemons.length} 只宝可梦数据`)
    } else {
      // 移除了控制台提示
    }
  } catch (error) {
    // 移除了控制台提示
  } finally {
    loading.value = false
  }
}

// 加载更多
const loadMore = () => {
  if (hasMore.value) {
    currentPage.value++
    updateDisplayList()
  }
}

// 选择宝可梦
const selectPokemon = (pokemon) => {
  console.log('点击宝可梦:', pokemon)
  router.push(`/pokemon/${pokemon.id}`)
}

// 获取默认图片
const getDefaultImage = (pokemon) => {
  // 使用Pokemon官方高质量artwork图片
  const id = pokemon.id || pokemon.number
  return `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/${id}.png`
}

// 获取宝可梦图片（带回退）
const getPokemonImage = (pokemon) => {
  return pokemon.imageUrl || pokemon.image_url || getDefaultImage(pokemon)
}

// 获取宝可梦名称
const getPokemonName = (pokemon) => {
  return pokemon.pokemonName || pokemon.pokemon_name || pokemon.name || '未知宝可梦'
}

// 获取宝可梦编号
const getPokemonNumber = (pokemon) => {
  return pokemon.number || pokemon.id?.toString().padStart(3, '0') || '000'
}

// 获取宝可梦属性
const getPokemonTypes = (pokemon) => {
  if (pokemon.types && Array.isArray(pokemon.types)) {
    // 如果types是对象数组，提取typeName，并去掉"系"字
    return pokemon.types.map(type => {
      const typeName = type.typeName || type
      return typeName.replace('系', '') // 去掉"系"字，例如"草系" -> "草"
    })
  }
  if (pokemon.type1) {
    const types = [pokemon.type1.replace('系', '')]
    if (pokemon.type2) {
      types.push(pokemon.type2.replace('系', ''))
    }
    return types
  }
  return ['一般'] // 默认属性
}

// 基础搜索功能
const performSearch = async () => {
  if (!searchKeyword.value.trim()) {
    // 如果搜索关键词为空，重新加载所有宝可梦
    await fetchPokemonList()
    return
  }
  
  try {
    loading.value = true
    const keyword = searchKeyword.value.trim()
    
    // 调用后端搜索API
    const response = await searchPokemon(keyword)
    const searchResults = Array.isArray(response) ? response : (response.data || [])
    
    allPokemonData.value = searchResults
    currentPage.value = 1
    updateDisplayList()
    
    // 检查搜索结果是否为空
    // 搜索完成
  } catch (error) {
    // 如果后端搜索失败，回退到本地搜索
    const keyword = searchKeyword.value.trim().toLowerCase()
    const filteredPokemons = allPokemonData.value.filter(pokemon => {
      // 按名称搜索
      const name = getPokemonName(pokemon).toLowerCase()
      if (name.includes(keyword)) return true
      
      // 按编号搜索（支持001、1等格式）
      const number = getPokemonNumber(pokemon)
      const id = pokemon.id?.toString() || ''
      if (number.includes(keyword) || id.includes(keyword)) return true
      
      return false
    })
    
    allPokemonData.value = filteredPokemons
    currentPage.value = 1
    updateDisplayList()
    
    // 本地搜索完成
  } finally {
    loading.value = false
  }
}

// 随机显示功能
const getRandomPokemon = () => {
  if (allPokemonData.value.length === 0) {
    return
  }
  
  // 随机打乱顺序后按分页显示（每次20只）
  const shuffled = [...allPokemonData.value].sort(() => 0.5 - Math.random())
  allPokemonData.value = shuffled
  currentPage.value = 1
  updateDisplayList()
}



// 切换属性筛选
const toggleType = (type) => {
  const index = selectedTypes.value.indexOf(type)
  if (index > -1) {
    selectedTypes.value.splice(index, 1)
  } else {
    // 最多选择2个属性
    if (selectedTypes.value.length >= 2) {
      return
    }
    selectedTypes.value.push(type)
  }
}

// 应用高级搜索
const applyAdvancedSearch = async () => {
  try {
    loading.value = true
    
    // 构建查询参数对象，确保参数类型正确
    const searchParams = {}
    
    // 添加基础搜索关键词（如果有）
    if (searchKeyword.value && searchKeyword.value.trim()) {
      searchParams.query = searchKeyword.value.trim()
    }
    
    // 添加属性筛选
    if (selectedTypes.value && selectedTypes.value.length > 0) {
      // 确保属性值不为空，并转换为英文
      const type1 = selectedTypes.value[0]
      if (type1 && type1.trim()) {
        searchParams.type1 = convertTypeToEnglish(type1.trim())
      }
      if (selectedTypes.value.length > 1) {
        const type2 = selectedTypes.value[1]
        if (type2 && type2.trim()) {
          searchParams.type2 = convertTypeToEnglish(type2.trim())
        }
      }
    }
    
    // 添加分类筛选
    if (selectedCategory.value && selectedCategory.value.trim()) {
      searchParams.category = selectedCategory.value.trim()
    }
    
    // 添加编号范围筛选，确保是有效的数字
    if (numberRange.value.min && numberRange.value.max && 
        numberRange.value.min > 0 && numberRange.value.max > 0 &&
        numberRange.value.min <= numberRange.value.max) {
      searchParams.beginNum = parseInt(numberRange.value.min)
      searchParams.endNum = parseInt(numberRange.value.max)
    }
    
    let response
    
    // 如果没有任何筛选条件，获取所有宝可梦
    if (Object.keys(searchParams).length === 0) {
      response = await getPokemonList()
    } else {
      // 使用VO方式进行组合查询
      response = await getPokemonListByVO(searchParams)
    }
    
    const searchResults = Array.isArray(response) ? response : (response.data || [])
    allPokemonData.value = searchResults
    currentPage.value = 1
    updateDisplayList()
    
    // 构建筛选条件描述
    const conditions = []
    if (searchKeyword.value.trim()) {
      conditions.push(`关键词: ${searchKeyword.value.trim()}`)
    }
    if (selectedTypes.value.length > 0) {
      conditions.push(`属性: ${selectedTypes.value.join('、')}`)
    }
    if (selectedCategory.value) {
      conditions.push(`分类: ${selectedCategory.value}`)
    }
    if (numberRange.value.min && numberRange.value.max) {
      conditions.push(`编号: ${numberRange.value.min}-${numberRange.value.max}`)
    }
    
    const conditionText = conditions.length > 0 ? ` (${conditions.join('，')})` : ''
    
    // 高级搜索完成
    
  } catch (error) {
    // 如果后端搜索失败，回退到本地搜索
    let filteredPokemons = [...allPokemonData.value]
    
    // 按属性筛选
    if (selectedTypes.value.length > 0) {
      filteredPokemons = filteredPokemons.filter(pokemon => {
        if (!pokemon.types || !Array.isArray(pokemon.types)) return false
        
        const pokemonTypeNames = pokemon.types.map(type => type.typeName || type.name || type)
        return selectedTypes.value.every(selectedType => 
          pokemonTypeNames.includes(selectedType)
        )
      })
    }
    
    // 按分类筛选
    if (selectedCategory.value) {
      filteredPokemons = filteredPokemons.filter(pokemon => 
        pokemon.category === selectedCategory.value
      )
    }
    
    // 按编号范围筛选
    if (numberRange.value.min && numberRange.value.max) {
      filteredPokemons = filteredPokemons.filter(pokemon => {
        const number = parseInt(pokemon.number || pokemon.id || 0)
        return number >= numberRange.value.min && number <= numberRange.value.max
      })
    }
    
    allPokemonData.value = filteredPokemons
    currentPage.value = 1
    updateDisplayList()
    
    // 检查本地搜索结果是否为空
    if (filteredPokemons.length === 0) {
      // 构建筛选条件描述（用于空结果提示）
      const conditions = []
      if (searchKeyword.value.trim()) {
        conditions.push(`关键词: ${searchKeyword.value.trim()}`)
      }
      if (selectedTypes.value.length > 0) {
        conditions.push(`属性: ${selectedTypes.value.join('、')}`)
      }
      if (selectedCategory.value) {
        conditions.push(`分类: ${selectedCategory.value}`)
      }
      if (numberRange.value.min && numberRange.value.max) {
        conditions.push(`编号: ${numberRange.value.min}-${numberRange.value.max}`)
      }
      const conditionText = conditions.length > 0 ? ` (${conditions.join('，')})` : ''
      
      // 本地筛选完成
    }
  } finally {
    loading.value = false
  }
}

// 滑块变化处理
const onRangeChange = (values) => {
  numberRange.value.min = values[0]
  numberRange.value.max = values[1]
  numberRange.value.values = values
}

// 滑块工具提示格式化
const formatTooltip = (value) => {
  return `No.${value}`
}

// 处理特性选择变化
const onCategoryChange = (value) => {
  selectedCategory.value = value
  // 如果用户输入了新的特性，进行模糊匹配
  if (value && !pokemonCategories.value.includes(value)) {
    console.log('用户输入了新的特性:', value)
    
    // 进行模糊匹配，找到最相似的特性
    const fuzzyMatch = findBestMatch(value, pokemonCategories.value)
    if (fuzzyMatch && fuzzyMatch.similarity > 0.5) {
      selectedCategory.value = fuzzyMatch.match
    } else {
      // 保持用户输入的值，让他们可以继续编辑
    }
  }
}

// 模糊匹配函数
const findBestMatch = (input, candidates) => {
  if (!input || !candidates || candidates.length === 0) return null
  
  let bestMatch = null
  let bestSimilarity = 0
  
  candidates.forEach(candidate => {
    const similarity = calculateSimilarity(input.toLowerCase(), candidate.toLowerCase())
    if (similarity > bestSimilarity) {
      bestSimilarity = similarity
      bestMatch = candidate
    }
  })
  
  return bestSimilarity > 0 ? { match: bestMatch, similarity: bestSimilarity } : null
}

// 计算字符串相似度（简单的编辑距离算法）
const calculateSimilarity = (str1, str2) => {
  const len1 = str1.length
  const len2 = str2.length
  
  if (len1 === 0) return len2 === 0 ? 1 : 0
  if (len2 === 0) return 0
  
  // 包含检查
  if (str1.includes(str2) || str2.includes(str1)) return 0.8
  
  // 编辑距离计算
  const matrix = Array(len1 + 1).fill().map(() => Array(len2 + 1).fill(0))
  
  for (let i = 0; i <= len1; i++) matrix[i][0] = i
  for (let j = 0; j <= len2; j++) matrix[0][j] = j
  
  for (let i = 1; i <= len1; i++) {
    for (let j = 1; j <= len2; j++) {
      const cost = str1[i - 1] === str2[j - 1] ? 0 : 1
      matrix[i][j] = Math.min(
        matrix[i - 1][j] + 1,      // 删除
        matrix[i][j - 1] + 1,      // 插入
        matrix[i - 1][j - 1] + cost // 替换
      )
    }
  }
  
  const distance = matrix[len1][len2]
  const maxLen = Math.max(len1, len2)
  return 1 - distance / maxLen
}

// 重置筛选条件
const resetFilters = async () => {
  searchKeyword.value = ''
  selectedTypes.value = []
  selectedCategory.value = ''
  numberRange.value = { min: 1, max: 166, values: [1, 166] }
  
  // 重新加载所有宝可梦数据
  await fetchPokemonList()
}

// 获取宝可梦主属性颜色渐变
const getPrimaryTypeGradient = (pokemon) => {
  if (!pokemon || !pokemon.types || pokemon.types.length === 0) {
    // 默认渐变
    return 'linear-gradient(145deg, #f0f2f5, #ffffff)'
  }
  
  // 获取第一个（主）属性的颜色
  const primaryType = pokemon.types[0]
  const typeName = (primaryType.typeName || primaryType).replace('系', '') // 去掉"系"字
  const primaryColor = typeColors[typeName] || '#f0f2f5'
  
  // 创建渐变效果，从属性色到白色
  return `linear-gradient(145deg, ${primaryColor}20, ${primaryColor}40, #ffffff)`
}

// 获取宝可梦主属性颜色（用于卡片背景）
const getPrimaryTypeColor = (pokemon) => {
  if (!pokemon || !pokemon.types || pokemon.types.length === 0) {
    return '#ffffff' // 默认白色
  }
  
  // 获取第一个（主）属性的颜色，并添加透明度
  const primaryType = pokemon.types[0]
  const typeName = (primaryType.typeName || primaryType).replace('系', '') // 去掉"系"字
  const primaryColor = typeColors[typeName] || '#f0f2f5'
  
  // 返回带有透明度的颜色，使背景不会太深
  return `${primaryColor}15` // 15是十六进制的透明度，约为8%
}

// 监听滑块值变化，实时更新显示
watch(() => numberRange.value.values, (newValues) => {
  if (newValues && newValues.length === 2) {
    numberRange.value.min = newValues[0]
    numberRange.value.max = newValues[1]
  }
}, { deep: true })

// 页面挂载时获取数据
onMounted(() => {
  fetchPokemonList()
})
</script>

<style scoped>
.home-page {
  padding: 40px 20px;
}

/* 标题区域 */
.title-section {
  text-align: center;
  margin-bottom: 50px;
}

.main-title {
  font-size: 3.5rem;
  font-weight: bold;
  color: #2c5aa0;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  animation: fadeInUp 1s ease-out;
}

.subtitle {
  font-size: 1.2rem;
  color: #666;
  margin: 10px 0 0 0;
  animation: fadeInUp 1s ease-out 0.2s both;
}

/* 宝可梦卡片网格 */
.pokemon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 30px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 宝可梦卡片 */
.pokemon-card {
  background: white;
  border-radius: 20px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  overflow: hidden;
  animation: fadeInScale 0.6s ease-out;
  position: relative;
  min-height: 320px;
  border: 3px solid #e9ecef;
}

.pokemon-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.card-inner {
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
}

.pokemon-number {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: bold;
}

.pokemon-image {
  width: 140px;
  height: 140px;
  margin: 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border: 3px solid #e9ecef;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

/* 精灵球背景图片 */
.pokemon-image::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 170px;
  height: 170px;
  transform: translate(-50%, -50%);
  background: url('@/assets/bk_pokemon_img.jpg') center/contain no-repeat;
  background-size: 100% 100%;
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
  border-radius: 50%;
  transition: opacity 0.3s ease;
}

/* 悬停时精灵球背景稍微加深 */
.pokemon-card:hover .pokemon-image::before {
  opacity: 0.18;
}

.pokemon-image img {
  position: relative;
  z-index: 2;
  max-width: 120px;
  max-height: 120px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.pokemon-name {
  font-size: 1.1rem;
  font-weight: bold;
  color: #333;
  margin: 0;
  line-height: 1.2;
}

.pokemon-types {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.type-badge {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  min-width: 40px;
  text-align: center;
}

/* 属性颜色 */
.type-草 { background: #78C850; }
.type-毒 { background: #A040A0; }
.type-火 { background: #F08030; }
.type-水 { background: #6890F0; }
.type-电 { background: #F8D030; }
.type-冰 { background: #98D8D8; }
.type-格斗 { background: #C03028; }
.type-地面 { background: #E0C068; }
.type-飞行 { background: #A890F0; }
.type-超能力 { background: #F85888; }
.type-虫 { background: #A8B820; }
.type-岩石 { background: #B8A038; }
.type-幽灵 { background: #705898; }
.type-龙 { background: #7038F8; }
.type-恶 { background: #705848; }
.type-钢 { background: #B8B8D0; }
.type-妖精 { background: #EE99AC; }
.type-一般 { background: #A8A878; }

/* 宝可梦底部信息区域 */
.pokemon-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.pokemon-name-section {
  flex: 1;
  text-align: center;
}

.pokemon-name {
  font-size: 1.2rem;
  font-weight: bold;
  color: #1a202c;
  margin: 0;
  line-height: 1.3;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}



.type-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
}



/* 搜索区域样式 */
.search-section {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto 40px auto;
  padding: 0 20px;
}

.basic-search {
  margin-bottom: 20px;
}

.search-bar {
  display: flex;
  gap: 15px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  max-width: 400px;
  min-width: 250px;
}

.el-button.search-btn, .el-button.random-btn, .el-button.list-btn {
  min-width: 120px;
  border-radius: 25px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  background-color: #1890ff !important;
  color: white !important;
  border: 1px solid #1890ff !important;
}

.el-button.search-btn:hover, .el-button.random-btn:hover, .el-button.list-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(24, 144, 255, 0.3);
  background-color: #096dd9 !important;
  color: white !important;
  border-color: #096dd9 !important;
}

/* 高级搜索切换按钮 */
.advanced-toggle {
  text-align: center;
  margin-bottom: 15px;
}

.advanced-toggle .el-button.el-button--info {
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 20px;
  transition: all 0.3s ease;
  background-color: #1890ff !important;
  color: white !important;
  border: 1px solid #1890ff !important;
}

.advanced-toggle .el-button.el-button--info:hover {
  background-color: #096dd9 !important;
  color: white !important;
  border-color: #096dd9 !important;
}

/* 高级搜索面板 */
.advanced-search {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.search-filters {
  display: flex;
  flex-direction: column;
  gap: 25px;
  margin-bottom: 25px;
}

.filter-section {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* 行布局的筛选器 */
.filter-section.filter-row {
  flex-direction: row;
  gap: 40px;
  align-items: flex-start;
}

.filter-column {
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex: 1;
}

.filter-column:first-child {
  flex: 2;
  max-width: 400px;
  min-width: 280px;
}

.filter-column:last-child {
  flex: 1;
  max-width: 280px;
  min-width: 240px;
}

.filter-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  border-bottom: 2px solid #667eea;
  padding-bottom: 8px;
}

.number-range-title {
  margin: 0 20px; /* 与 .number-range-slider .el-slider 的左右 20px 保持一致 */
}

/* 属性筛选样式 */
.type-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.type-filter {
  cursor: pointer;
  transition: all 0.3s ease;
  transform: scale(1);
  border: none;
  outline: none;
  background: none;
  padding: 0;
}

.type-filter:hover {
  transform: scale(1.05);
}

.type-filter.active {
  transform: scale(1.1);
}

.type-filter .type-badge {
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  display: inline-block;
  transition: all 0.3s ease;
  border: none;
  outline: none;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* 未选中状态 - 半透明 + 灰度 */
.type-filter:not(.active) .type-badge {
  opacity: 0.6;
  filter: grayscale(0.4) brightness(0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* 选中状态 - 亮丽 + 阴影 + 边框高亮 */
.type-filter.active .type-badge {
  opacity: 1;
  filter: grayscale(0) brightness(1.15) saturate(1.2);
  box-shadow: 
    0 4px 15px rgba(0, 0, 0, 0.25),
    0 0 0 4px rgba(255, 255, 255, 0.9),
    0 0 25px rgba(255, 255, 255, 0.5),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
  transform: translateY(-2px) scale(1.02);
}

/* 悬停状态 */
.type-filter:hover:not(.active) .type-badge {
  opacity: 0.8;
  filter: grayscale(0.2) brightness(1);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

.type-filter:hover.active .type-badge {
  box-shadow: 
    0 8px 25px rgba(0, 0, 0, 0.3),
    0 0 0 5px rgba(255, 255, 255, 1),
    0 0 35px rgba(255, 255, 255, 0.6),
    inset 0 1px 3px rgba(255, 255, 255, 0.4);
  transform: translateY(-3px) scale(1.05);
  filter: grayscale(0) brightness(1.2) saturate(1.3);
}

/* 确保按钮没有默认样式 */
.type-filter:focus {
  outline: none;
  border: none;
}

.type-filter:active {
  outline: none;
  border: none;
}

/* 移除任何可能的默认按钮样式 */
.type-filter {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: transparent;
  border: 0;
  margin: 0;
  box-sizing: border-box;
}

/* 确保type-badge没有任何边框 */
.type-filter .type-badge {
  border: none !important;
  outline: none !important;
  box-sizing: border-box;
}

/* 选中状态的脉冲动画效果 */
.type-filter.active .type-badge::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 35px;
  background: linear-gradient(45deg, 
    rgba(255, 255, 255, 0.4) 0%, 
    rgba(255, 255, 255, 0.2) 25%,
    rgba(255, 255, 255, 0.1) 50%, 
    rgba(255, 255, 255, 0.2) 75%,
    rgba(255, 255, 255, 0.4) 100%);
  animation: pulse-glow 3s ease-in-out infinite;
  z-index: -1;
}

@keyframes pulse-glow {
  0%, 100% { 
    opacity: 0.5; 
    transform: scale(1); 
  }
  25% { 
    opacity: 0.8; 
    transform: scale(1.01); 
  }
  50% { 
    opacity: 1; 
    transform: scale(1.03); 
  }
  75% { 
    opacity: 0.8; 
    transform: scale(1.01); 
  }
}

/* 特性选择器样式优化 */
.category-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-section .el-select {
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.category-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #666;
  opacity: 0.8;
  transition: all 0.3s ease;
}

.category-hint:hover {
  opacity: 1;
  color: #1890ff;
}

.category-hint .el-icon {
  font-size: 14px;
}

.filter-section .el-select:hover {
  box-shadow: 0 6px 20px rgba(24, 144, 255, 0.2);
  transform: translateY(-1px);
}

.filter-section .el-select .el-input__wrapper {
  border-radius: 15px;
  border: 2px solid #e4e7ed;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
}

.filter-section .el-select .el-input__wrapper:hover {
  border-color: #1890ff;
  box-shadow: 0 0 10px rgba(24, 144, 255, 0.2);
}

.filter-section .el-select .el-input__wrapper.is-focus {
  border-color: #1890ff;
  box-shadow: 0 0 15px rgba(24, 144, 255, 0.3);
}

.filter-section .el-select .el-input__inner {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.filter-section .el-select .el-input__inner::placeholder {
  color: #999;
  font-style: italic;
}

/* 下拉面板样式 */
.el-select-dropdown {
  border-radius: 12px;
  border: 1px solid #e4e7ed;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.el-select-dropdown .el-select-dropdown__item {
  border-radius: 8px;
  margin: 2px 8px;
  transition: all 0.2s ease;
  font-weight: 500;
}

.el-select-dropdown .el-select-dropdown__item:hover {
  background: linear-gradient(135deg, #1890ff, #096dd9);
  color: white;
  transform: translateX(2px);
}

.el-select-dropdown .el-select-dropdown__item.selected {
  background: linear-gradient(135deg, #1890ff, #096dd9);
  color: white;
  font-weight: 600;
}

/* 编号范围筛选样式 */
.number-range-slider {
  position: relative;
  padding: 20px 0;
}

.number-range-slider .el-slider {
  margin: 0 20px;
}

.number-range-slider .el-slider__runway {
  height: 8px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 4px;
  position: relative;
}

.number-range-slider .el-slider__bar {
  background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
  border-radius: 4px;
  height: 8px;
}

.number-range-slider .el-slider__button-wrapper {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #4facfe;
  box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
  transition: all 0.3s ease;
}

.number-range-slider .el-slider__button-wrapper:hover {
  transform: scale(1.2);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.5);
}

.number-range-slider .el-slider__button-wrapper.hover,
.number-range-slider .el-slider__button-wrapper.dragging {
  transform: scale(1.3);
  box-shadow: 0 8px 25px rgba(79, 172, 254, 0.6);
}

.number-range-slider .el-slider__button {
  width: 14px;
  height: 14px;
  background: linear-gradient(45deg, #4facfe 0%, #00f2fe 100%);
  border: none;
  border-radius: 50%;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding: 0 20px;
  font-size: 12px;
  color: #8892b0;
  font-weight: 500;
}

.range-label-min,
.range-label-max {
  position: relative;
}

.range-label-min::before,
.range-label-max::before {
  content: 'No.';
  font-weight: 600;
  color: #64748b;
}

/* 搜索操作按钮 */
.search-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.search-actions .el-button {
  min-width: 120px;
  border-radius: 25px;
  font-weight: 600;
  padding: 12px 24px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  background-color: #1890ff !important;
  color: white !important;
  border: 1px solid #1890ff !important;
}

.search-actions .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(24, 144, 255, 0.3);
  background-color: #096dd9 !important;
  color: white !important;
  border-color: #096dd9 !important;
}

/* 加载更多按钮 */
.load-more {
  text-align: center;
  margin-top: 50px;
}

/* 确保加载更多按钮为蓝色主题并不被覆盖 */
.load-more .el-button {
  min-width: 140px;
  border-radius: 25px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  background-color: #1890ff !important;
  color: white !important;
  border: 1px solid #1890ff !important;
}

.load-more .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(24, 144, 255, 0.3);
  background-color: #096dd9 !important;
  color: white !important;
  border-color: #096dd9 !important;
}

/* 加载状态 */
.loading-state {
  text-align: center;
  padding: 100px 0;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  color: #666;
}

.loading-content p {
  margin-top: 20px;
  font-size: 1.1rem;
}

/* 精灵球加载动画 */
.pokeball-loading {
  display: inline-block;
}

.pokeball {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  position: relative;
  animation: pokeball-spin 2s linear infinite;
}

.pokeball-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border-radius: 60px 60px 0 0;
  border: 3px solid #333;
  border-bottom: 2px solid #333;
}

.pokeball-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(135deg, #ffffff, #f8f9fa);
  border-radius: 0 0 60px 60px;
  border: 3px solid #333;
  border-top: 2px solid #333;
}

.pokeball-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background: #ffffff;
  border: 4px solid #333;
  border-radius: 50%;
  z-index: 10;
}

.pokeball-center::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: #333;
  border-radius: 50%;
}

@keyframes pokeball-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 100px 0;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-content {
  color: #999;
  max-width: 400px;
}

.empty-content h3 {
  color: #666;
  font-size: 1.5rem;
  margin: 20px 0 10px 0;
}

.empty-content p {
  color: #999;
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 30px;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.5;
}

/* 详情弹窗 */
.pokemon-detail {
  display: flex;
  gap: 30px;
  align-items: flex-start;
}

.detail-image {
  flex-shrink: 0;
}

.detail-image img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  background: linear-gradient(145deg, #f0f2f5, #ffffff);
  border-radius: 20px;
  padding: 20px;
}

.detail-info {
  flex: 1;
}

.detail-info p {
  margin: 15px 0;
  font-size: 1.1rem;
  line-height: 1.6;
}

.detail-info strong {
  color: #2c5aa0;
  margin-right: 8px;
}

/* 动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-title {
    font-size: 2.5rem;
  }
  
  .pokemon-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    padding: 0 10px;
  }
  
  .pokemon-bottom {
    gap: 10px;
  }
  
  .pokemon-name {
    font-size: 1rem;
  }
  
  .pokemon-type-colors {
    width: 20px;
    height: 32px;
  }
  
  /* 移动端精灵球背景调整 */
  .pokemon-image::before {
    width: 100px;
    height: 100px;
  }
  
  .pokemon-image img {
    max-width: 85px;
    max-height: 85px;
  }
  
  .pokemon-detail {
    flex-direction: column;
    text-align: center;
  }
  
  .detail-image img {
    width: 150px;
    height: 150px;
  }
  
  .search-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-input {
    max-width: none;
  }
  
  .search-btn, .random-btn, .list-btn {
    min-width: auto;
  }
  
  .advanced-search {
    padding: 20px;
  }
  
  .search-filters {
    gap: 20px;
  }
  
  .type-filters {
    justify-content: center;
  }
  
  .number-range-slider {
    padding: 15px 0;
  }
  
  .number-range-slider .el-slider {
    margin: 0 10px;
  }
  
  .range-labels {
    padding: 0 10px;
  }
  
  .search-actions {
    flex-direction: column;
  }
  
  /* 小屏幕上行布局改为列布局 */
  .filter-section.filter-row {
    flex-direction: column;
    gap: 20px;
  }
  
  .filter-column:first-child {
    max-width: none;
    min-width: auto;
    flex: none;
  }
  
  .filter-column:last-child {
    max-width: none;
    min-width: auto;
    flex: none;
  }
}

@media (max-width: 480px) {
  .main-title {
    font-size: 2rem;
  }
  
  .pokemon-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .home-page {
    padding: 20px 10px;
  }
}

.reset-btn {
  color: white !important;
}
</style>